package com.hand.demo.api.controller.v1;

import io.choerodon.core.domain.Page;
import io.choerodon.core.iam.ResourceLevel;
import io.choerodon.mybatis.pagehelper.annotation.SortDefault;
import io.choerodon.mybatis.pagehelper.domain.PageRequest;
import io.choerodon.mybatis.pagehelper.domain.Sort;
import io.choerodon.swagger.annotation.Permission;
import io.swagger.annotations.ApiOperation;
import org.hzero.core.base.BaseController;
import org.hzero.core.util.Results;
import org.hzero.mybatis.helper.SecurityTokenHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.hand.demo.app.service.HhrTaSkillsService;
import com.hand.demo.domain.entity.HhrTaSkills;
import com.hand.demo.domain.repository.HhrTaSkillsRepository;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * 技能表(HhrTaSkills)表控制层
 *
 * @author
 * @since 2025-06-16 12:16:52
 */

@RestController("hhrTaSkillsController.v1")
@RequestMapping("/v1/{organizationId}/hhr-ta-skillss")
public class HhrTaSkillsController extends BaseController {

    @Autowired
    private HhrTaSkillsRepository hhrTaSkillsRepository;

    @Autowired
    private HhrTaSkillsService hhrTaSkillsService;

    @ApiOperation(value = "技能表列表")
    @Permission(level = ResourceLevel.ORGANIZATION)
    @GetMapping
    public ResponseEntity<Page<HhrTaSkills>> list(HhrTaSkills hhrTaSkills, @PathVariable Long organizationId,
                                                  @ApiIgnore @SortDefault(value = HhrTaSkills.FIELD_ID,
                                                          direction = Sort.Direction.DESC) PageRequest pageRequest) {
        Page<HhrTaSkills> list = hhrTaSkillsService.selectList(pageRequest, hhrTaSkills);
        return Results.success(list);
    }

    @ApiOperation(value = "技能表明细")
    @Permission(level = ResourceLevel.ORGANIZATION)
    @GetMapping("/{id}/detail")
    public ResponseEntity<HhrTaSkills> detail(@PathVariable Long id) {
        HhrTaSkills hhrTaSkills = hhrTaSkillsRepository.selectByPrimary(id);
        return Results.success(hhrTaSkills);
    }

    @ApiOperation(value = "创建或更新技能表")
    @Permission(level = ResourceLevel.ORGANIZATION)
    @PostMapping
    public ResponseEntity<List<HhrTaSkills>> save(@PathVariable Long organizationId, @RequestBody List<HhrTaSkills> hhrTaSkillss) {
        validObject(hhrTaSkillss);
        SecurityTokenHelper.validTokenIgnoreInsert(hhrTaSkillss);
        hhrTaSkillss.forEach(item -> item.setTenantId(organizationId));
        hhrTaSkillsService.saveData(hhrTaSkillss);
        return Results.success(hhrTaSkillss);
    }

    @ApiOperation(value = "删除技能表")
    @Permission(level = ResourceLevel.ORGANIZATION)
    @DeleteMapping
    public ResponseEntity<?> remove(@RequestBody List<HhrTaSkills> hhrTaSkillss) {
        SecurityTokenHelper.validToken(hhrTaSkillss);
        hhrTaSkillsRepository.batchDeleteByPrimaryKey(hhrTaSkillss);
        return Results.success();
    }

}

